package com.example.tnot.Teacher.Homepart.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tnot.R;
import com.example.tnot.Teacher.Homepart.ItemBean.rv_frequentlyListItem;
import com.example.tnot.Teacher.MinePart.InternalFragment.AboutStu.adapter.StudentAdapter;

import java.util.ArrayList;
import java.util.List;

public class FrequentlyAdapter extends RecyclerView.Adapter<FrequentlyAdapter.ViewHolder>{
    ImageButton ib_icon;
    TextView tv_message;
    List<rv_frequentlyListItem> data = new ArrayList();
    int ClickItem;

    public FrequentlyAdapter(List data) {
        this.data = data;
    }

    @NonNull
    @Override
    public FrequentlyAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_rv_frequently, parent, false);
        return new FrequentlyAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull FrequentlyAdapter.ViewHolder holder, int position) {
        ib_icon.setImageResource(data.get(position).getImageResourceId());
        tv_message.setText(data.get(position).getText());
        tv_message.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                //静态点击我的常用
                ClickItem = holder.getBindingAdapterPosition();
                SwitchToSonFragment(ClickItem, navController);
            }
        });
        ib_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                //静态点击我的常用
                ClickItem = holder.getBindingAdapterPosition();
                SwitchToSonFragment(ClickItem, navController);
            }
        });

    }

    @Override
    public int getItemCount() {
        return data.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ib_icon = itemView.findViewById(R.id.ib_icon);
            tv_message = itemView.findViewById(R.id.tv_message);
        }
    }

//我的常用 点击跳转方法
    private void SwitchToSonFragment(int clickItem, NavController navController) {
        switch (ClickItem) {
            case 0:
                navController.navigate(R.id.action_homeContainerFragment_to_agentFragment);
                break;
            case 1:
                navController.navigate(R.id.action_homeContainerFragment_to_collectFragment3);
                break;
            case 2:
                navController.navigate(R.id.action_homeContainerFragment_to_notManageFragment);
                break;
            case 3:
                navController.navigate(R.id.action_homeContainerFragment_to_courseListFragment);
                break;
            case 4:
                navController.navigate(R.id.action_homeContainerFragment_to_messageFragment);
                break;
            case 5:
                navController.navigate(R.id.action_homeContainerFragment_to_messageFragment);
                break;
            case 6:
                navController.navigate(R.id.action_homeContainerFragment_to_messageFragment);
                break;
            case 7:
                navController.navigate(R.id.action_homeContainerFragment_to_dynamicHomeFragment);
                break;
            // 添加更多 case 处理其他导航
            default:
                break;
        }
    }
}

